function InspectOffsetSearch(fileStations,OptsGen,OptPre)
%InspectOffsetSearch - Inspection of several time series and offsets search
%
%   InspectOffsetSearch(filenaStations,OptsGen,OptPre)
%
% This function allows the inspection of GNSS time series on the stations
% listed in filenaStations in accordance with the StaVelMain options stored
% in the struct variable OptsGen. 
% This function requires the availability of tsData files related to the   
% listed stations.
%
% Input variables:
%
% - filenaStations carries the list of GNSS stations, represented by their 
%   standard 4-character names. This file can be either an Excel or an 
%   ASCII file. In the case of Excel file, the station names must be placed
%   in the first column (no more than the first column is read). 
%   In the case of an ASCII file, only a column is admitted. 
%   If filenaStations is undefined or empty, the filename can be managed 
%   in interactive way.
%   Let statName be the string array with the station names.
%
% - OptsGen is a struct variable generated by means of geneOpts function.
%   The input tsData file is searched of the basis of the station name, 
%   statName(k), and information carried by OptsGen in accordance with:
%   filenats = fullfile(OptsGen.dirTs,[statName(k) OptsGen.AddTs '.mat']).
%   The tsData file is upgraded according to the detected offsets.
%   The corresponding mom observation files, whose names are stored in 
%   OptsGen, are also generated and/or upgraded.
%   If OptsGen is undefined or empty, the .mat file with such a struct
%   variable can be interactively managed. 
%
% - If OptPre is undefined, empty or false, no possible already available 
%   data about offsests are used, i.e. the offsets search is carried out 
%   starting from scratch.
%   If OptPre is true, for each station the offsets search starts from the 
%   offsets resulting from the corresponding tsData object.
%
% See also InspOffsetMom, StaVelMain, geneOpts, OptsGenLoad.

% G. Teza, 2022

if (nargin < 3) || isempty(OptPre)
    OptPre = 0;
end
OptPre = logical(OptPre);
if nargin < 2
    OptsGen = [];
end
if nargin < 1 
    fileStations = [];
end    

b = readStationList(fileStations);
if isempty(b) 
    return
else
    nin = size(b,1);
end

OptsGen = OptsGenLoad(OptsGen);
if isempty(OptsGen)
    return
end

for k = 1:nin
    
    namek = b{k,1};
    namek = strtrim(namek);     % to remove possible leading and trailing spaces
    namek = upper(namek);       % to warrant station name with capital letters
    if isempty(namek)
        continue
    end
    namek = upper(namek);
    
    InspOffsetMom(namek,OptsGen,[],OptPre);
    
end